/**  
 * @date 2023-11-24 
 * @author Zhang Yu
 */
package com.jwt.shiro.demo.controller;

import java.io.UnsupportedEncodingException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.jwt.shiro.demo.model.ResultMap;
import com.jwt.shiro.demo.util.JWTUtil;


/**  
 * @description: TODO
 */
@RestController
public class LoginController {
	
	@Autowired
    ResultMap resultMap;
	
	@PostMapping("/login")
    public ResultMap login(@RequestParam("username") String username) {
		return resultMap.success().code(200).message(JWTUtil.createToken(username));
    }

    @RequestMapping(path = "/unauthorized/{message}")
    public ResultMap unauthorized(@PathVariable String message) throws UnsupportedEncodingException {
        return resultMap.success().code(401).message(message);
    }
}
